#!/bin/bash

# $Header: /opt/unixmon/tools/DNS/RCS/reload-zone,v 1.1 2012/11/27 07:50:51 yajin Exp $
# Author: yang.jin@ebay.com


export PATH=/bin:/usr/bin

DNS_SERVERS_LIST="/etc/named/IT_DNS_SERVERS"
RNDC="/opt/bind/sbin/rndc"
LOG="/var/adm/zonereload.log"

if [ ! -f $DNS_SERVERS_LIST ]; then
        echo -e "The configuration file \"$DNS_SERVERS_LIST\" does not exist."
        exit 2
fi

. $DNS_SERVERS_LIST


if [ $# -ne 1 ]; then
	echo "Usage: $0 zone-name"
	exit 1
fi

# Added By Albert to track the zone reload history
echo "`date` reload zone $1 " >> $LOG

for host in $DNS_PRIMARY_MASTER $DNS_PSEUDO_MASTERS; do
	echo -e "Reloading the zone \"$1\" on $host...\t\t\c"
	ssh $host "$RNDC reload $1"
done

sleep 5

for host in $DNS_SLAVES; do
	echo -e "Reloading the zone \"$1\" on $host...\t\t\c"
	ssh $host "$RNDC reload $1"
done
